package config

import (
	"gopkg.in/yaml.v2"
	"io/ioutil"
)

// 配置

type ConfigStruct struct {
	PathCode string
	Url string
	Suffix string
	EolDomain string
	HttpPort string
}

type configYaml struct {
	PathCode string `yaml:"path_code"`
	Url string `yaml:"url"`
	Suffix string `yaml:"suffix"`
	EolDomain string `yaml:"eol_domain"`
	HttpPort string `yaml:"http_port"`
}

var Config *ConfigStruct

func init() {
	configYamlData := getConfigFromYaml()

	Config = &ConfigStruct{
		PathCode: configYamlData.PathCode,
		Url:      configYamlData.Url,
		Suffix:   configYamlData.Suffix,
		EolDomain: configYamlData.EolDomain,
		HttpPort: configYamlData.HttpPort,
	}
}

func (c *ConfigStruct) GetPath() string {
	return c.PathCode
}

func (c *ConfigStruct) GetUrl() string {
	return c.Url
}

func(c *ConfigStruct) GetSuffix() string {
	return c.Suffix
}

func getConfigFromYaml() configYaml {
	path := "./config.yaml"
	content, err := ioutil.ReadFile(path)
	if err != nil {
		panic(err)
	}

	res := configYaml{}
	err = yaml.Unmarshal(content, &res)
	if err != nil {
		panic(err)
	}
	return res
}